package com.shinetech.repository;

import com.shinetech.entity.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by joy on 2017/7/2.
 */
@Repository
public interface MenuRepository extends BaseRepository<Menu>{

    @Query("select distinct t from ResourceAuthority ra , Menu t where ra.resourceId = t.id" +
            " and  ra.authorityType = 'group' " +
            " and ra.resourceType = 'menu'" +
            " and ra.authorityId in (select  u.group.id from User u where u.id =?1 )" )
    public List<Menu> getMenusByUserId(long userId) ;


}
